home *** CD-ROM | disk | FTP | other *** search
/ Acorn RISC PD-CD 1 / Acorn RISC PD-CD 1.iso / games / _kalaha / source / c / redraw < prev    next >
Encoding:
Text File  |  1992-03-04  |  3.9 KB  |  182 lines

  1.  
  2. #include "kalaha.h"
  3.  
  4.  
  5.  
  6. static void plot_arrow(wimp_redrawstr r);
  7.  
  8. static void find_hollow_details(int *nump, int *xp, int *yp, char *name, int p, wimp_redrawstr r);
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15. void plot_arrow(wimp_redrawstr r)
  16. {
  17. int x, y;
  18. char              name[12];
  19. sprite_factors scales;
  20. sprite_pixtrans   cols[16];
  21. sprite_id        sid;
  22.  
  23.  
  24. sid.tag = sprite_id_name;
  25. sid.s.name = name;
  26. x = coords_x_toscreen(SIDEBORDER+5*HOLLWID/2, (coords_cvtstr *)&r.box);
  27. y = coords_y_toscreen(MIDROW, (coords_cvtstr *)&r.box);
  28.  
  29. if (botgo) 
  30.   {
  31.   strcpy(name, "dnarrow");
  32.   }
  33. else
  34.   {
  35.   if (automove  ||  starterplayer == UservUser)
  36.     strcpy(name, "uparrow");
  37.   else
  38.     strcpy(name, "uparrow_c");
  39.   }
  40. wimpt_noerr(wimp_readpixtrans(resspr_area(), &sid, &scales, cols));
  41. wimpt_noerr(sprite_put_scaled(resspr_area(), &sid, 0, x, y, &scales, cols));
  42.  
  43. }
  44.  
  45.  
  46.  
  47.  
  48. void find_hollow_details(int *nump, int *xp, int *yp, char *name, int p, wimp_redrawstr r)
  49. {
  50. if (p==6 || p==13)
  51.   {
  52.   strcpy(name, "bighollow");
  53.   *yp = coords_y_toscreen(MIDROW, (coords_cvtstr *)&r.box);
  54.   if (p==6)
  55.      {
  56.      *xp = coords_x_toscreen(SIDEBORDER+4*HOLLWID, (coords_cvtstr *)&r.box);
  57.      *nump = bottot;
  58.      }
  59.   else
  60.      {
  61.      *xp = coords_x_toscreen(SIDEBORDER    , (coords_cvtstr *)&r.box); 
  62.      *nump = toptot;
  63.      }
  64.   }
  65. else
  66.   {
  67.   strcpy(name, "hollow");
  68.   if (p<6)
  69.     {
  70.     *xp = coords_x_toscreen(SIDEBORDER+p*HOLLWID, (coords_cvtstr *)&r.box);
  71.     *yp = coords_y_toscreen(BOTROW, (coords_cvtstr *)&r.box);
  72.     *nump = bot[p];
  73.     }
  74.   else
  75.     {
  76.     *xp = coords_x_toscreen(SIDEBORDER+(12-p)*HOLLWID, (coords_cvtstr *)&r.box);
  77.     *yp = coords_y_toscreen(TOPROW, (coords_cvtstr *)&r.box);
  78.     *nump = top[p-7];
  79.     }
  80.   }
  81. }
  82.  
  83.  
  84.  
  85.  
  86.  
  87. void plot_one_hollow(int p, wimp_redrawstr r)
  88. {
  89. /* p is 0...13 or >=14.  >=14 means arrow, others c-clockwise from bot left */
  90.  
  91. char              name[12];
  92. sprite_factors scales;
  93. sprite_pixtrans   cols[16];
  94. sprite_id        sid;
  95. int num, x, y, n, roomfor;
  96.  
  97. static char spiral1[30][2] = { {2,2}, {2,4}, {4,4}, {4,2}, {4,0}, {2,0},
  98. {0,0}, {0,2}, {0,4}, {0,6}, {2,6}, {4,6}, {6,6}, {6,4}, {6,2}, {6,0},
  99. {3,3}, {3,1}, {1,1}, {1,3}, {1,5}, {3,5}, {5,5}, {5,3}, {5,1},
  100. {2,2}, {2,4}, {4,4}, {4,2}, {3,3} };
  101.  
  102. static char spiral2[53][2] = { {2,2}, {4,2}, {6,2}, {8,2}, {10,2}, {12,2},
  103.                     {12,4}, {10,4}, {8,4}, {6,4}, {4,4}, {2,4}, {0,4},
  104.    {0,2},         {0,0}, {2,0}, {4,0}, {6,0}, {8,0}, {10,0}, {12,0}, {14,0}, 
  105. {14,2}, {14,4},   {14,6}, {12,6}, {10,6}, {8,6}, {6,6}, {4,6}, {2,6}, {0,6},
  106.  
  107.          {3,3}, {5,3},  {7,3}, {9,3}, {11,3}, {13,3}, 
  108.          {13,5}, {11,5}, {9,5}, {7,5}, {5,5}, {3,5}, {1,5}, 
  109.  {1,3},  {1,1}, {3,1},{5,1},{7,1},{9,1},{11,1},{13,1} }; 
  110.  
  111.  
  112. sid.tag = sprite_id_name;
  113. sid.s.name = name;
  114.  
  115.  
  116. if (p>=14)
  117.   {
  118.   plot_arrow(r);
  119.   return;
  120.   }
  121.  
  122. find_hollow_details(&num, &x, &y, name, p, r);
  123. /* now x,y is bottomleft of relevant hollow, and sprite named */
  124.  
  125. wimpt_noerr(wimp_readpixtrans(resspr_area(), &sid, &scales, cols));
  126. wimpt_noerr(sprite_put_scaled(resspr_area(), &sid, 0, x, y, &scales, cols));
  127. if (num == 0) return;
  128.  
  129. strcpy(name, "gb");
  130. wimpt_noerr(wimp_readpixtrans(resspr_area(), &sid, &scales, cols));
  131.  
  132.  
  133. roomfor = (p==6 || p==13) ? 67 : 30 ;
  134. n = 0;
  135. while ( n < roomfor  &&  n < num  )
  136.   {
  137.   int xx, yy;
  138.   if (p==6 || p==13)
  139.     {
  140.     xx = x + spiral2[n%53][0]*HALFBALL + 12;
  141.     yy = y + spiral2[n%53][1]*HALFBALL + 4;
  142.     }
  143.   else
  144.     {
  145.     xx = x + spiral1[n][0]*HALFBALL + 4;
  146.     yy = y + spiral1[n][1]*HALFBALL + 4;
  147.     }
  148.   wimpt_noerr(sprite_put_scaled(resspr_area(), &sid, 8, xx, yy, &scales, cols));
  149.   n++;
  150.   }
  151. }
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158. void redraw_main_window(wimp_w handle)
  159. {
  160. int            more;
  161. wimp_redrawstr r;
  162. int p;
  163. wimp_box hollow;
  164.  
  165. r.w = handle;
  166. wimpt_noerr(wimp_redraw_wind(&r, &more));
  167.  
  168. while (more)
  169.   {
  170.   for (p=0; p<15; p++)
  171.     {
  172.     find_hollow_box(&hollow, p);
  173.     coords_box_toscreen(&hollow, (coords_cvtstr *)&r.box );
  174.     if (coords_boxesoverlap(&hollow, &r.g))
  175.         {plot_one_hollow(p, r);}
  176.     }
  177.   wimpt_noerr(wimp_get_rectangle(&r, &more));
  178.   }
  179.  
  180. }
  181.  
  182.